/*
 * Copyright (C) 2025 Tsingteng MicroSystem
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include "nfc_transport_api.h"
#include <memory>

tNFC_STATUS tp_get_vnd_config(tNFC_VENDOR_CONFIG *config);

class TransportAdaptation {
public:
    static TransportAdaptation& GetInstance();

    TransportAdaptation(const TransportAdaptation&) = delete;
    TransportAdaptation& operator=(const TransportAdaptation&) = delete;
    tNFC_STATUS Open(tNFC_EVENT_CALLBACK event_cb, tNFC_DATA_CALLBACK data_cb);
    tNFC_STATUS Close(tNFC_CLOSE_TYPE type);
    tNFC_STATUS CoreInitialized();
    tNFC_STATUS FactoryReset();
    tNFC_STATUS CheckFirmware();
    tNFC_STATUS GetExtConfig(tNFC_CONFIG_MANAGER *cm);
    tNFC_STATUS GetConfig(tNFC_CONFIG_MANAGER *cm);
    tNFC_STATUS PowerCycle();
    tNFC_STATUS PreDiscovery();
    tNFC_STATUS Write(const uint8_t* p_data, uint16_t data_len);
    bool IsConfigModified();

private:
    TransportAdaptation();
    ~TransportAdaptation();
    friend struct std::default_delete<TransportAdaptation>;
    static std::unique_ptr<TransportAdaptation> instance;
    void InitializeHalService();
    static void hal_check_firmware_callback(tNFC_EVENT event,
                                              tNFC_STATUS event_status);
    static void hal_check_firmware_data_callback(uint16_t data_len,
                                                  uint8_t* p_data);
    static void AddHdiDeathRecipient();
    static void RemoveHdiDeathRecipient();
    void Finalize();
};

enum {
    IOCTL_GET_CONFIG_EXT = 0,
    IOCTL_GET_CONFIG_MODIFIED_STATUS = 1,

    IOCTL_MAX,
};

enum {
    FILE_TYPE_TMS = 0,
    FILE_TYPE_RF,
};
